package com.su.sweet.socket;

import org.smartboot.socket.MessageProcessor;
import org.smartboot.socket.transport.AioSession;
import org.smartboot.socket.transport.WriteBuffer;

import java.io.IOException;

public class MessageProcessorImpl implements MessageProcessor<String> {
    @Override
    public void process(AioSession session, String msg) {
        System.out.println("receive from client: " + msg);
        WriteBuffer outputStream = session.writeBuffer();
        try {
            byte[] bytes = msg.getBytes();
            outputStream.writeInt(bytes.length);
            outputStream.write(bytes);
        } catch (IOException e) {
            e.printStackTrace();
        }
    }
}
